import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import plotly
import plotly.express as px
import plotly.graph_objs as go
import os
zomato=pd.read_csv('D:\\PYTHON\\zomato.csv')
zomato
| url | address | name | online_order | book_table | rate | votes | phone | location | rest_type | dish_liked | cuisines | approx_cost(for two people) | reviews_list | menu_item | listed_in(type) | listed_in(city) | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | https://www.zomato.com/bangalore/jalsa-banasha... | 942, 21st Main Road, 2nd Stage, Banashankari, ... | Jalsa | Yes | Yes | 4.1/5 | 775 | 080 42297555\r\n+91 9743772233 | Banashankari | Casual Dining | Pasta, Lunch Buffet, Masala Papad, Paneer Laja... | North Indian, Mughlai, Chinese | 800 | [('Rated 4.0', 'RATED\n A beautiful place to ... | [] | Buffet | Banashankari |
| 1 | https://www.zomato.com/bangalore/spice-elephan... | 2nd Floor, 80 Feet Road, Near Big Bazaar, 6th ... | Spice Elephant | Yes | No | 4.1/5 | 787 | 080 41714161 | Banashankari | Casual Dining | Momos, Lunch Buffet, Chocolate Nirvana, Thai G... | Chinese, North Indian, Thai | 800 | [('Rated 4.0', 'RATED\n Had been here for din... | [] | Buffet | Banashankari |
| 2 | https://www.zomato.com/SanchurroBangalore?cont... | 1112, Next to KIMS Medical College, 17th Cross... | San Churro Cafe | Yes | No | 3.8/5 | 918 | +91 9663487993 | Banashankari | Cafe, Casual Dining | Churros, Cannelloni, Minestrone Soup, Hot Choc... | Cafe, Mexican, Italian | 800 | [('Rated 3.0', "RATED\n Ambience is not that ... | [] | Buffet | Banashankari |
| 3 | https://www.zomato.com/bangalore/addhuri-udupi... | 1st Floor, Annakuteera, 3rd Stage, Banashankar... | Addhuri Udupi Bhojana | No | No | 3.7/5 | 88 | +91 9620009302 | Banashankari | Quick Bites | Masala Dosa | South Indian, North Indian | 300 | [('Rated 4.0', "RATED\n Great food and proper... | [] | Buffet | Banashankari |
| 4 | https://www.zomato.com/bangalore/grand-village... | 10, 3rd Floor, Lakshmi Associates, Gandhi Baza... | Grand Village | No | No | 3.8/5 | 166 | +91 8026612447\r\n+91 9901210005 | Basavanagudi | Casual Dining | Panipuri, Gol Gappe | North Indian, Rajasthani | 600 | [('Rated 4.0', 'RATED\n Very good restaurant ... | [] | Buffet | Banashankari |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 51712 | https://www.zomato.com/bangalore/best-brews-fo... | Four Points by Sheraton Bengaluru, 43/3, White... | Best Brews - Four Points by Sheraton Bengaluru... | No | No | 3.6 /5 | 27 | 080 40301477 | Whitefield | Bar | NaN | Continental | 1,500 | [('Rated 5.0', "RATED\n Food and service are ... | [] | Pubs and bars | Whitefield |
| 51713 | https://www.zomato.com/bangalore/vinod-bar-and... | Number 10, Garudachar Palya, Mahadevapura, Whi... | Vinod Bar And Restaurant | No | No | NaN | 0 | +91 8197675843 | Whitefield | Bar | NaN | Finger Food | 600 | [] | [] | Pubs and bars | Whitefield |
| 51714 | https://www.zomato.com/bangalore/plunge-sherat... | Sheraton Grand Bengaluru Whitefield Hotel & Co... | Plunge - Sheraton Grand Bengaluru Whitefield H... | No | No | NaN | 0 | NaN | Whitefield | Bar | NaN | Finger Food | 2,000 | [] | [] | Pubs and bars | Whitefield |
| 51715 | https://www.zomato.com/bangalore/chime-sherato... | Sheraton Grand Bengaluru Whitefield Hotel & Co... | Chime - Sheraton Grand Bengaluru Whitefield Ho... | No | Yes | 4.3 /5 | 236 | 080 49652769 | ITPL Main Road, Whitefield | Bar | Cocktails, Pizza, Buttermilk | Finger Food | 2,500 | [('Rated 4.0', 'RATED\n Nice and friendly pla... | [] | Pubs and bars | Whitefield |
| 51716 | https://www.zomato.com/bangalore/the-nest-the-... | ITPL Main Road, KIADB Export Promotion Industr... | The Nest - The Den Bengaluru | No | No | 3.4 /5 | 13 | +91 8071117272 | ITPL Main Road, Whitefield | Bar, Casual Dining | NaN | Finger Food, North Indian, Continental | 1,500 | [('Rated 5.0', 'RATED\n Great ambience , look... | [] | Pubs and bars | Whitefield |
51717 rows × 17 columns
zomato['location'].nunique()
93
zomato.shape
(51717, 17)
zomato.columns
Index(['url', 'address', 'name', 'online_order', 'book_table', 'rate', 'votes',
'phone', 'location', 'rest_type', 'dish_liked', 'cuisines',
'approx_cost(for two people)', 'reviews_list', 'menu_item',
'listed_in(type)', 'listed_in(city)'],
dtype='object')
zomato.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 51717 entries, 0 to 51716 Data columns (total 17 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 url 51717 non-null object 1 address 51717 non-null object 2 name 51717 non-null object 3 online_order 51717 non-null object 4 book_table 51717 non-null object 5 rate 43942 non-null object 6 votes 51717 non-null int64 7 phone 50509 non-null object 8 location 51696 non-null object 9 rest_type 51490 non-null object 10 dish_liked 23639 non-null object 11 cuisines 51672 non-null object 12 approx_cost(for two people) 51371 non-null object 13 reviews_list 51717 non-null object 14 menu_item 51717 non-null object 15 listed_in(type) 51717 non-null object 16 listed_in(city) 51717 non-null object dtypes: int64(1), object(16) memory usage: 6.7+ MB
zomato['location'].unique()
array(['Banashankari', 'Basavanagudi', 'Mysore Road', 'Jayanagar',
'Kumaraswamy Layout', 'Rajarajeshwari Nagar', 'Vijay Nagar',
'Uttarahalli', 'JP Nagar', 'South Bangalore', 'City Market',
'Nagarbhavi', 'Bannerghatta Road', 'BTM', 'Kanakapura Road',
'Bommanahalli', nan, 'CV Raman Nagar', 'Electronic City', 'HSR',
'Marathahalli', 'Sarjapur Road', 'Wilson Garden', 'Shanti Nagar',
'Koramangala 5th Block', 'Koramangala 8th Block', 'Richmond Road',
'Koramangala 7th Block', 'Jalahalli', 'Koramangala 4th Block',
'Bellandur', 'Whitefield', 'East Bangalore', 'Old Airport Road',
'Indiranagar', 'Koramangala 1st Block', 'Frazer Town', 'RT Nagar',
'MG Road', 'Brigade Road', 'Lavelle Road', 'Church Street',
'Ulsoor', 'Residency Road', 'Shivajinagar', 'Infantry Road',
'St. Marks Road', 'Cunningham Road', 'Race Course Road',
'Commercial Street', 'Vasanth Nagar', 'HBR Layout', 'Domlur',
'Ejipura', 'Jeevan Bhima Nagar', 'Old Madras Road', 'Malleshwaram',
'Seshadripuram', 'Kammanahalli', 'Koramangala 6th Block',
'Majestic', 'Langford Town', 'Central Bangalore', 'Sanjay Nagar',
'Brookefield', 'ITPL Main Road, Whitefield',
'Varthur Main Road, Whitefield', 'KR Puram',
'Koramangala 2nd Block', 'Koramangala 3rd Block', 'Koramangala',
'Hosur Road', 'Rajajinagar', 'Banaswadi', 'North Bangalore',
'Nagawara', 'Hennur', 'Kalyan Nagar', 'New BEL Road', 'Jakkur',
'Rammurthy Nagar', 'Thippasandra', 'Kaggadasapura', 'Hebbal',
'Kengeri', 'Sankey Road', 'Sadashiv Nagar', 'Basaveshwara Nagar',
'Yeshwantpur', 'West Bangalore', 'Magadi Road', 'Yelahanka',
'Sahakara Nagar', 'Peenya'], dtype=object)
zomato.isnull().sum()
url 0 address 0 name 0 online_order 0 book_table 0 rate 7775 votes 0 phone 1208 location 21 rest_type 227 dish_liked 28078 cuisines 45 approx_cost(for two people) 346 reviews_list 0 menu_item 0 listed_in(type) 0 listed_in(city) 0 dtype: int64
zomato['location'].unique()
array(['Banashankari', 'Basavanagudi', 'Mysore Road', 'Jayanagar',
'Kumaraswamy Layout', 'Rajarajeshwari Nagar', 'Vijay Nagar',
'Uttarahalli', 'JP Nagar', 'South Bangalore', 'City Market',
'Nagarbhavi', 'Bannerghatta Road', 'BTM', 'Kanakapura Road',
'Bommanahalli', nan, 'CV Raman Nagar', 'Electronic City', 'HSR',
'Marathahalli', 'Sarjapur Road', 'Wilson Garden', 'Shanti Nagar',
'Koramangala 5th Block', 'Koramangala 8th Block', 'Richmond Road',
'Koramangala 7th Block', 'Jalahalli', 'Koramangala 4th Block',
'Bellandur', 'Whitefield', 'East Bangalore', 'Old Airport Road',
'Indiranagar', 'Koramangala 1st Block', 'Frazer Town', 'RT Nagar',
'MG Road', 'Brigade Road', 'Lavelle Road', 'Church Street',
'Ulsoor', 'Residency Road', 'Shivajinagar', 'Infantry Road',
'St. Marks Road', 'Cunningham Road', 'Race Course Road',
'Commercial Street', 'Vasanth Nagar', 'HBR Layout', 'Domlur',
'Ejipura', 'Jeevan Bhima Nagar', 'Old Madras Road', 'Malleshwaram',
'Seshadripuram', 'Kammanahalli', 'Koramangala 6th Block',
'Majestic', 'Langford Town', 'Central Bangalore', 'Sanjay Nagar',
'Brookefield', 'ITPL Main Road, Whitefield',
'Varthur Main Road, Whitefield', 'KR Puram',
'Koramangala 2nd Block', 'Koramangala 3rd Block', 'Koramangala',
'Hosur Road', 'Rajajinagar', 'Banaswadi', 'North Bangalore',
'Nagawara', 'Hennur', 'Kalyan Nagar', 'New BEL Road', 'Jakkur',
'Rammurthy Nagar', 'Thippasandra', 'Kaggadasapura', 'Hebbal',
'Kengeri', 'Sankey Road', 'Sadashiv Nagar', 'Basaveshwara Nagar',
'Yeshwantpur', 'West Bangalore', 'Magadi Road', 'Yelahanka',
'Sahakara Nagar', 'Peenya'], dtype=object)
zomato['rest_type'].value_counts()
Quick Bites 19132
Casual Dining 10330
Cafe 3732
Delivery 2604
Dessert Parlor 2263
...
Dessert Parlor, Kiosk 2
Food Court, Beverage Shop 2
Dessert Parlor, Food Court 2
Sweet Shop, Dessert Parlor 1
Quick Bites, Kiosk 1
Name: rest_type, Length: 93, dtype: int64
zomato.duplicated().sum()
0
zomato
| url | address | name | online_order | book_table | rate | votes | phone | location | rest_type | dish_liked | cuisines | approx_cost(for two people) | reviews_list | menu_item | listed_in(type) | listed_in(city) | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | https://www.zomato.com/bangalore/jalsa-banasha... | 942, 21st Main Road, 2nd Stage, Banashankari, ... | Jalsa | Yes | Yes | 4.1/5 | 775 | 080 42297555\r\n+91 9743772233 | Banashankari | Casual Dining | Pasta, Lunch Buffet, Masala Papad, Paneer Laja... | North Indian, Mughlai, Chinese | 800 | [('Rated 4.0', 'RATED\n A beautiful place to ... | [] | Buffet | Banashankari |
| 1 | https://www.zomato.com/bangalore/spice-elephan... | 2nd Floor, 80 Feet Road, Near Big Bazaar, 6th ... | Spice Elephant | Yes | No | 4.1/5 | 787 | 080 41714161 | Banashankari | Casual Dining | Momos, Lunch Buffet, Chocolate Nirvana, Thai G... | Chinese, North Indian, Thai | 800 | [('Rated 4.0', 'RATED\n Had been here for din... | [] | Buffet | Banashankari |
| 2 | https://www.zomato.com/SanchurroBangalore?cont... | 1112, Next to KIMS Medical College, 17th Cross... | San Churro Cafe | Yes | No | 3.8/5 | 918 | +91 9663487993 | Banashankari | Cafe, Casual Dining | Churros, Cannelloni, Minestrone Soup, Hot Choc... | Cafe, Mexican, Italian | 800 | [('Rated 3.0', "RATED\n Ambience is not that ... | [] | Buffet | Banashankari |
| 3 | https://www.zomato.com/bangalore/addhuri-udupi... | 1st Floor, Annakuteera, 3rd Stage, Banashankar... | Addhuri Udupi Bhojana | No | No | 3.7/5 | 88 | +91 9620009302 | Banashankari | Quick Bites | Masala Dosa | South Indian, North Indian | 300 | [('Rated 4.0', "RATED\n Great food and proper... | [] | Buffet | Banashankari |
| 4 | https://www.zomato.com/bangalore/grand-village... | 10, 3rd Floor, Lakshmi Associates, Gandhi Baza... | Grand Village | No | No | 3.8/5 | 166 | +91 8026612447\r\n+91 9901210005 | Basavanagudi | Casual Dining | Panipuri, Gol Gappe | North Indian, Rajasthani | 600 | [('Rated 4.0', 'RATED\n Very good restaurant ... | [] | Buffet | Banashankari |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 51712 | https://www.zomato.com/bangalore/best-brews-fo... | Four Points by Sheraton Bengaluru, 43/3, White... | Best Brews - Four Points by Sheraton Bengaluru... | No | No | 3.6 /5 | 27 | 080 40301477 | Whitefield | Bar | NaN | Continental | 1,500 | [('Rated 5.0', "RATED\n Food and service are ... | [] | Pubs and bars | Whitefield |
| 51713 | https://www.zomato.com/bangalore/vinod-bar-and... | Number 10, Garudachar Palya, Mahadevapura, Whi... | Vinod Bar And Restaurant | No | No | NaN | 0 | +91 8197675843 | Whitefield | Bar | NaN | Finger Food | 600 | [] | [] | Pubs and bars | Whitefield |
| 51714 | https://www.zomato.com/bangalore/plunge-sherat... | Sheraton Grand Bengaluru Whitefield Hotel & Co... | Plunge - Sheraton Grand Bengaluru Whitefield H... | No | No | NaN | 0 | NaN | Whitefield | Bar | NaN | Finger Food | 2,000 | [] | [] | Pubs and bars | Whitefield |
| 51715 | https://www.zomato.com/bangalore/chime-sherato... | Sheraton Grand Bengaluru Whitefield Hotel & Co... | Chime - Sheraton Grand Bengaluru Whitefield Ho... | No | Yes | 4.3 /5 | 236 | 080 49652769 | ITPL Main Road, Whitefield | Bar | Cocktails, Pizza, Buttermilk | Finger Food | 2,500 | [('Rated 4.0', 'RATED\n Nice and friendly pla... | [] | Pubs and bars | Whitefield |
| 51716 | https://www.zomato.com/bangalore/the-nest-the-... | ITPL Main Road, KIADB Export Promotion Industr... | The Nest - The Den Bengaluru | No | No | 3.4 /5 | 13 | +91 8071117272 | ITPL Main Road, Whitefield | Bar, Casual Dining | NaN | Finger Food, North Indian, Continental | 1,500 | [('Rated 5.0', 'RATED\n Great ambience , look... | [] | Pubs and bars | Whitefield |
51717 rows × 17 columns
#pip install geopy
#pip install chart-studio
from geopy.geocoders import Nominatim
# libraries for displaying images
from IPython.display import Image
from IPython.core.display import HTML
from folium.plugins import FloatImage
import folium # plotting library
import matplotlib.pyplot as plt
import seaborn as sns
import chart_studio.plotly as py
location = [x for x in zomato['location'].unique().tolist() if type(x) == str] latitude = [] longitude = [] for i in range(0, len(location)): if(type(location[i]) == str): ctr=0 while True: try: address = location[i] + ', Bengaluru, India' geolocator = Nominatim(user_agent="ny_explorer") loc = geolocator.geocode(address) latitude.append(loc.latitude) longitude.append(loc.longitude) print('The geograpical coordinate of location are {}, {}.'.format(loc.latitude, loc.longitude)) except: ctr+=1 if(ctr==7): print(i) latitude.append(address) longitude.append(address) break continue break
#zomato['location_latitude'] = zomato['location'].map(dict(zip(location, latitude)))
#zomato['location_longitude'] = zomato['location'].map(dict(zip(location, longitude)))
zomato
| url | address | name | online_order | book_table | rate | votes | phone | location | rest_type | dish_liked | cuisines | approx_cost(for two people) | reviews_list | menu_item | listed_in(type) | listed_in(city) | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | https://www.zomato.com/bangalore/jalsa-banasha... | 942, 21st Main Road, 2nd Stage, Banashankari, ... | Jalsa | Yes | Yes | 4.1/5 | 775 | 080 42297555\r\n+91 9743772233 | Banashankari | Casual Dining | Pasta, Lunch Buffet, Masala Papad, Paneer Laja... | North Indian, Mughlai, Chinese | 800 | [('Rated 4.0', 'RATED\n A beautiful place to ... | [] | Buffet | Banashankari |
| 1 | https://www.zomato.com/bangalore/spice-elephan... | 2nd Floor, 80 Feet Road, Near Big Bazaar, 6th ... | Spice Elephant | Yes | No | 4.1/5 | 787 | 080 41714161 | Banashankari | Casual Dining | Momos, Lunch Buffet, Chocolate Nirvana, Thai G... | Chinese, North Indian, Thai | 800 | [('Rated 4.0', 'RATED\n Had been here for din... | [] | Buffet | Banashankari |
| 2 | https://www.zomato.com/SanchurroBangalore?cont... | 1112, Next to KIMS Medical College, 17th Cross... | San Churro Cafe | Yes | No | 3.8/5 | 918 | +91 9663487993 | Banashankari | Cafe, Casual Dining | Churros, Cannelloni, Minestrone Soup, Hot Choc... | Cafe, Mexican, Italian | 800 | [('Rated 3.0', "RATED\n Ambience is not that ... | [] | Buffet | Banashankari |
| 3 | https://www.zomato.com/bangalore/addhuri-udupi... | 1st Floor, Annakuteera, 3rd Stage, Banashankar... | Addhuri Udupi Bhojana | No | No | 3.7/5 | 88 | +91 9620009302 | Banashankari | Quick Bites | Masala Dosa | South Indian, North Indian | 300 | [('Rated 4.0', "RATED\n Great food and proper... | [] | Buffet | Banashankari |
| 4 | https://www.zomato.com/bangalore/grand-village... | 10, 3rd Floor, Lakshmi Associates, Gandhi Baza... | Grand Village | No | No | 3.8/5 | 166 | +91 8026612447\r\n+91 9901210005 | Basavanagudi | Casual Dining | Panipuri, Gol Gappe | North Indian, Rajasthani | 600 | [('Rated 4.0', 'RATED\n Very good restaurant ... | [] | Buffet | Banashankari |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 51712 | https://www.zomato.com/bangalore/best-brews-fo... | Four Points by Sheraton Bengaluru, 43/3, White... | Best Brews - Four Points by Sheraton Bengaluru... | No | No | 3.6 /5 | 27 | 080 40301477 | Whitefield | Bar | NaN | Continental | 1,500 | [('Rated 5.0', "RATED\n Food and service are ... | [] | Pubs and bars | Whitefield |
| 51713 | https://www.zomato.com/bangalore/vinod-bar-and... | Number 10, Garudachar Palya, Mahadevapura, Whi... | Vinod Bar And Restaurant | No | No | NaN | 0 | +91 8197675843 | Whitefield | Bar | NaN | Finger Food | 600 | [] | [] | Pubs and bars | Whitefield |
| 51714 | https://www.zomato.com/bangalore/plunge-sherat... | Sheraton Grand Bengaluru Whitefield Hotel & Co... | Plunge - Sheraton Grand Bengaluru Whitefield H... | No | No | NaN | 0 | NaN | Whitefield | Bar | NaN | Finger Food | 2,000 | [] | [] | Pubs and bars | Whitefield |
| 51715 | https://www.zomato.com/bangalore/chime-sherato... | Sheraton Grand Bengaluru Whitefield Hotel & Co... | Chime - Sheraton Grand Bengaluru Whitefield Ho... | No | Yes | 4.3 /5 | 236 | 080 49652769 | ITPL Main Road, Whitefield | Bar | Cocktails, Pizza, Buttermilk | Finger Food | 2,500 | [('Rated 4.0', 'RATED\n Nice and friendly pla... | [] | Pubs and bars | Whitefield |
| 51716 | https://www.zomato.com/bangalore/the-nest-the-... | ITPL Main Road, KIADB Export Promotion Industr... | The Nest - The Den Bengaluru | No | No | 3.4 /5 | 13 | +91 8071117272 | ITPL Main Road, Whitefield | Bar, Casual Dining | NaN | Finger Food, North Indian, Continental | 1,500 | [('Rated 5.0', 'RATED\n Great ambience , look... | [] | Pubs and bars | Whitefield |
51717 rows × 17 columns
locations = {'Nagawara':'north_bangalore', 'Hennur':'north_bangalore', 'Kalyan Nagar':'north_bangalore',
'New BEL Road':'north_bangalore', 'Jakkur':'north_bangalore', 'Rammurthy Nagar':'north_bangalore',
'Thippasandra':'north_bangalore', 'Kaggadasapura':'north_bangalore', 'Hebbal':'north_bangalore',
'Kengeri':'north_bangalore', 'Sankey Road':'north_bangalore', 'Sadashiv Nagar':'north_bangalore',
'Basaveshwara Nagar':'north_bangalore', 'Yeshwantpur':'north_bangalore', 'Peenya':'north_bangalore',
'Banashankari':'south_bangalore', 'Basavanagudi':'south_bangalore', 'Mysore Road':'south_bangalore',
'Jayanagar':'south_bangalore', 'Kumaraswamy Layout':'south_bangalore', 'Rajarajeshwari Nagar':'south_bangalore',
'Vijay Nagar':'south_bangalore', 'Uttarahalli':'south_bangalore', 'JP Nagar':'south_bangalore',
'City Market':'south_bangalore', 'Nagarbhavi':'south_bangalore', 'Bannerghatta Road':'south_bangalore',
'BTM':'south_bangalore', 'Kanakapura Road':'south_bangalore', 'Bommanahalli':'south_bangalore',
'Electronic City':'south_bangalore', 'HSR':'south_bangalore', 'Wilson Garden':'south_bangalore',
'Shanti Nagar':'south_bangalore', 'Koramangala 5th Block':'south_bangalore',
'Koramangala 8th Block':'south_bangalore', 'Richmond Road':'south_bangalore',
'Koramangala 7th Block':'south_bangalore', 'Jalahalli':'south_bangalore', 'Koramangala 4th Block':'south_bangalore',
'Bellandur':'south_bangalore', 'Old Airport Road':'east_bangalore', 'Indiranagar':'east_bangalore',
'Koramangala 1st Block':'east_bangalore', 'Frazer Town':'east_bangalore', 'RT Nagar':'east_bangalore',
'MG Road':'east_bangalore', 'Brigade Road':'east_bangalore', 'Lavelle Road':'east_bangalore',
'Church Street':'east_bangalore', 'Ulsoor':'east_bangalore', 'Residency Road':'east_bangalore',
'Shivajinagar':'east_bangalore', 'Infantry Road':'east_bangalore', 'St. Marks Road':'east_bangalore',
'Cunningham Road':'east_bangalore', 'Race Course Road':'east_bangalore', 'Commercial Street':'east_bangalore',
'Vasanth Nagar':'east_bangalore', 'HBR Layout':'east_bangalore', 'Domlur':'east_bangalore',
'Ejipura':'east_bangalore', 'Jeevan Bhima Nagar':'east_bangalore', 'Old Madras Road':'east_bangalore',
'Malleshwaram':'east_bangalore', 'Seshadripuram':'east_bangalore', 'Kammanahalli':'east_bangalore',
'Koramangala 6th Block':'east_bangalore', 'Majestic':'east_bangalore', 'Langford Town':'east_bangalore',
'Central Bangalore':'west_bangalore', 'Sanjay Nagar':'west_bangalore', 'Brookefield':'west_bangalore',
'ITPL Main Road ,Whitefield':'west_bangalore', 'Varthur Main Road, Whitefield':'west_bangalore',
'KR Puram':'west_bangalore', 'Koramangala 2nd Block':'west_bangalore', 'Koramangala 3rd Block':'west_bangalore',
'Koramangala':'west_bangalore', 'Hosur Road':'west_bangalore', 'Rajajinagar':'west_bangalore',
'Banaswadi':'west_bangalore', 'Yelahanka':'west_bangalore', 'Sahakara Nagar':'west_bangalore',
'Magadi Road':'west_bangalore','Whitefield':'east_bangalore','Marathahalli':'east_bangalore','East Bangalore':'east_bangalore',
'South Bangalore':'south_bangalore','North Bangalore':'north_bangalore','Sarjapur Road':'east_bangalore',
'CV Raman Nagar':'east_bangalore','ITPL Main Road, Whitefield':'east_bangalore','West Bangalore':'west_bangalore'}
zomato['location']=zomato['location'].replace(locations)
#Renaming few columns name
zomato = zomato.rename(columns={'approx_cost(for two people)':'cost','listed_in(type)':'type','listed_in(city)':'city'})
zomato.head()
| url | address | name | online_order | book_table | rate | votes | phone | location | rest_type | dish_liked | cuisines | cost | reviews_list | menu_item | type | city | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | https://www.zomato.com/bangalore/jalsa-banasha... | 942, 21st Main Road, 2nd Stage, Banashankari, ... | Jalsa | Yes | Yes | 4.1/5 | 775 | 080 42297555\r\n+91 9743772233 | south_bangalore | Casual Dining | Pasta, Lunch Buffet, Masala Papad, Paneer Laja... | North Indian, Mughlai, Chinese | 800 | [('Rated 4.0', 'RATED\n A beautiful place to ... | [] | Buffet | Banashankari |
| 1 | https://www.zomato.com/bangalore/spice-elephan... | 2nd Floor, 80 Feet Road, Near Big Bazaar, 6th ... | Spice Elephant | Yes | No | 4.1/5 | 787 | 080 41714161 | south_bangalore | Casual Dining | Momos, Lunch Buffet, Chocolate Nirvana, Thai G... | Chinese, North Indian, Thai | 800 | [('Rated 4.0', 'RATED\n Had been here for din... | [] | Buffet | Banashankari |
| 2 | https://www.zomato.com/SanchurroBangalore?cont... | 1112, Next to KIMS Medical College, 17th Cross... | San Churro Cafe | Yes | No | 3.8/5 | 918 | +91 9663487993 | south_bangalore | Cafe, Casual Dining | Churros, Cannelloni, Minestrone Soup, Hot Choc... | Cafe, Mexican, Italian | 800 | [('Rated 3.0', "RATED\n Ambience is not that ... | [] | Buffet | Banashankari |
| 3 | https://www.zomato.com/bangalore/addhuri-udupi... | 1st Floor, Annakuteera, 3rd Stage, Banashankar... | Addhuri Udupi Bhojana | No | No | 3.7/5 | 88 | +91 9620009302 | south_bangalore | Quick Bites | Masala Dosa | South Indian, North Indian | 300 | [('Rated 4.0', "RATED\n Great food and proper... | [] | Buffet | Banashankari |
| 4 | https://www.zomato.com/bangalore/grand-village... | 10, 3rd Floor, Lakshmi Associates, Gandhi Baza... | Grand Village | No | No | 3.8/5 | 166 | +91 8026612447\r\n+91 9901210005 | south_bangalore | Casual Dining | Panipuri, Gol Gappe | North Indian, Rajasthani | 600 | [('Rated 4.0', 'RATED\n Very good restaurant ... | [] | Buffet | Banashankari |
zomato['location'].value_counts()
south_bangalore 25016 east_bangalore 21363 west_bangalore 2699 north_bangalore 2618 Name: location, dtype: int64
zom=zomato[zomato['location']=='south_bangalore']
chains=zom['name'].value_counts()[:10]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous restaurant chains in south banglore",
titlefont={'size': 25},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
chains=zom['cuisines'].value_counts()[:15]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous restaurant cusinies in south banglore",
titlefont={'size': 25},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
chains=zom['dish_liked'].value_counts()[:15]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous dishliked in south banglore",
titlefont={'size': 20},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
zom1=zomato[zomato['location']=='north_bangalore']
chains=zom1['name'].value_counts()[:10]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous restaurant chains in north banglore",
titlefont={'size': 25},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
chains=zom1['cuisines'].value_counts()[:15]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous restaurant cuisines in north banglore",
titlefont={'size': 25},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
chains=zom1['dish_liked'].value_counts()[:15]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous dishliked in north banglore",
titlefont={'size': 20},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
zom2=zomato[zomato['location']=='east_bangalore']
chains=zom2['name'].value_counts()[:10]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous restaurant chains in east banglore",
titlefont={'size': 25},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
chains=zom2['cuisines'].value_counts()[:15]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous restaurant cuisines in east banglore",
titlefont={'size': 25},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
chains=zom2['dish_liked'].value_counts()[:15]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous dishliked in east banglore",
titlefont={'size': 20},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
zom3=zomato[zomato['location']=='west_bangalore']
chains=zom3['name'].value_counts()[:10]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous restaurant chains in west banglore",
titlefont={'size': 25},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
chains=zom2['cuisines'].value_counts()[:15]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous restaurant cuisines in west banglore",
titlefont={'size': 25},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
chains=zom3['dish_liked'].value_counts()[:15]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous dishliked in west banglore",
titlefont={'size': 20},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
zomato['cost'] = zomato['cost'].astype(str)
zomato['cost'] = zomato['cost'].apply(lambda x: x.replace(',','.'))
zomato['cost'] = zomato['cost'].astype(float)
zomato.name = zomato.name.apply(lambda x:x.title())
zomato.online_order.replace(('Yes','No'),(True, False),inplace=True)
zomato.book_table.replace(('Yes','No'),(True, False),inplace=True)
def Encode(zomato):
for column in zomato.columns[~zomato.columns.isin(['rate', 'cost', 'votes'])]:
zomato[column] = zomato[column].factorize()[0]
return zomato
df_zom = Encode(zomato.copy())
df_zom.head()
| url | address | name | online_order | book_table | rate | votes | phone | location | rest_type | dish_liked | cuisines | cost | reviews_list | menu_item | type | city | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 4.1/5 | 775 | 0 | 0 | 0 | 0 | 0 | 800.0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 | 1 | 4.1/5 | 787 | 1 | 0 | 0 | 1 | 1 | 800.0 | 1 | 0 | 0 | 0 |
| 2 | 2 | 2 | 2 | 0 | 1 | 3.8/5 | 918 | 2 | 0 | 1 | 2 | 2 | 800.0 | 2 | 0 | 0 | 0 |
| 3 | 3 | 3 | 3 | 1 | 1 | 3.7/5 | 88 | 3 | 0 | 2 | 3 | 3 | 300.0 | 3 | 0 | 0 | 0 |
| 4 | 4 | 4 | 4 | 1 | 1 | 3.8/5 | 166 | 4 | 0 | 0 | 4 | 4 | 600.0 | 4 | 0 | 0 | 0 |
corr = df_zom.corr(method='kendall')
plt.figure(figsize=(12,6))
sns.heatmap(corr, annot=True)
<AxesSubplot:>
labels = ["Accepted",'Not Accepted']
values = zomato['online_order'].value_counts()
colors = ['lightskyblue', 'tomato']
fig = go.Figure(data=[go.Pie(labels=labels,
values=values,hole=.3)])
fig.update_traces(hoverinfo='label+percent', textinfo='value', textfont_size=20,
marker=dict(colors=colors, line=dict(color='#000000', width=3)))
fig.update_layout(title="Online delivering available? ",
titlefont={'size': 30},
)
fig.show()
From the above donut chart we observed that 58.9% were those who accepting Online delivery
labels = ["Accepted",'Not Accepted']
values = zomato['book_table'].value_counts()
colors = ['lightskyblue', 'lightgreen']
fig = go.Figure(data=[go.Pie(labels=labels,
values=values,hole=.3)])
fig.update_traces(hoverinfo='label+percent', textinfo='value', textfont_size=20,
marker=dict(colors=colors, line=dict(color='#000000', width=3)))
fig.update_layout(title="Table booking available? ",
titlefont={'size': 30},
)
fig.show()
import plotly.express as px
values = zomato['cuisines'].value_counts()[:15]
fig = px.bar(values, x=values.index, y=values.values, labels={'x':'Cuisine', 'y':'Number of Restaurants'})
fig.update_layout(title="Most popular cuisines of Bangalore",
titlefont={'size': 25})
fig.show()
From the above donut chart we observed that 12.5% were those who not accepting Online Table Booking
values = zomato['cuisines'].value_counts()[:15]
labels=values.index
text=values.index
fig = go.Figure(data=[go.Pie(values=values,labels=labels,hole=.3)])
fig.update_traces(hoverinfo='label+percent', textinfo='value', textfont_size=20,
marker=dict(line=dict(color='#000000', width=3)))
fig.update_layout(title="Most popular cuisines of Bangalore ",
titlefont={'size': 25},
)
fig.show()
From the above donut chart we can see that North Indian and North Indian, Chinese were the most popular cuisines of Bangalore
fig = px.box(zomato,x='online_order',y='cost',color='online_order')
fig.update_layout(title="Cost comparison for Online order",
titlefont={'size': 25},template='simple_white'
)
fig.show()
From the above boxplots we can see that false boxplot contains an outlier, this must be because of noise data (present there)
fig=px.bar(x=zomato['city'].unique(),y=zomato['city'].value_counts(),labels=dict(x="City Name",y="Total Count"),color_continuous_scale="rainbow",color=zomato['city'].unique())
fig.update_layout(title="Location wise counts for Restaurants ",
titlefont={'size': 25},template='simple_white'
)
fig.update_traces(marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
From the above bar graphs we saw that Banashankari is the location which had highest number of restaurants present
df1=zomato.copy()
df1.dropna(how='any',inplace=True)
loc_plt=pd.crosstab(df1['rate'],df1['city'])
fig=px.bar(loc_plt,x=loc_plt.index,y=loc_plt.columns,barmode='stack',opacity=1)
fig.update_layout(title="Location wise Rating",
titlefont={'size': 25},
template='simple_white'
)
fig.update_traces(marker_line_color='black',
marker_line_width=0.5, opacity=0.8)
fig.show()
From the above graph we observed that 3.9 rating has the highest tower in terms of location wise rating
fig=px.histogram(zomato['type'],labels=dict(value='Type'))
fig.update_layout(title="Type of Services",
titlefont={'size': 25},template='simple_white'
)
fig.update_traces(marker_color='tomato', marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
From the above we observed that Delivery has the highest bar tower and Dine-out also, in terms of Type of Services
fig=px.histogram(zomato['cost'],labels=dict(value='Cost Range'),nbins=10)
fig.update_layout(title="Cost of Restaurants",
titlefont={'size': 25},template='simple_white'
)
fig.update_traces(marker_color='lightskyblue', marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
From the above graph we can see that 300-399 is the highest bar graph in terms of range of cost
chains=zomato['name'].value_counts()[:10]
fig=px.bar(y=chains,x=chains.index,labels=dict(x='Name',y='Count'),color_continuous_scale="rainbow",color=chains.index)
fig.update_layout(title="Most famous restaurant chains",
titlefont={'size': 25},template='simple_white'
)
fig.update_traces( marker_line_color='black',
marker_line_width=2, opacity=1)
fig.show()
From the above we saw that Cafe Coffee Day and Onesta has high bar towers
zomato['rate'] = zomato.rate.replace('NEW', np.NaN)
zomato['rate'].unique()
array(['4.1/5', '3.8/5', '3.7/5', '3.6/5', '4.6/5', '4.0/5', '4.2/5',
'3.9/5', '3.1/5', '3.0/5', '3.2/5', '3.3/5', '2.8/5', '4.4/5',
'4.3/5', nan, '2.9/5', '3.5/5', '2.6/5', '3.8 /5', '3.4/5',
'4.5/5', '2.5/5', '2.7/5', '4.7/5', '2.4/5', '2.2/5', '2.3/5',
'3.4 /5', '-', '3.6 /5', '4.8/5', '3.9 /5', '4.2 /5', '4.0 /5',
'4.1 /5', '3.7 /5', '3.1 /5', '2.9 /5', '3.3 /5', '2.8 /5',
'3.5 /5', '2.7 /5', '2.5 /5', '3.2 /5', '2.6 /5', '4.5 /5',
'4.3 /5', '4.4 /5', '4.9/5', '2.1/5', '2.0/5', '1.8/5', '4.6 /5',
'4.9 /5', '3.0 /5', '4.8 /5', '2.3 /5', '4.7 /5', '2.4 /5',
'2.1 /5', '2.2 /5', '2.0 /5', '1.8 /5'], dtype=object)
zomato['rate'] = zomato.rate.replace('-', np.NaN)
zomato['rate'].unique()
array(['4.1/5', '3.8/5', '3.7/5', '3.6/5', '4.6/5', '4.0/5', '4.2/5',
'3.9/5', '3.1/5', '3.0/5', '3.2/5', '3.3/5', '2.8/5', '4.4/5',
'4.3/5', nan, '2.9/5', '3.5/5', '2.6/5', '3.8 /5', '3.4/5',
'4.5/5', '2.5/5', '2.7/5', '4.7/5', '2.4/5', '2.2/5', '2.3/5',
'3.4 /5', '3.6 /5', '4.8/5', '3.9 /5', '4.2 /5', '4.0 /5',
'4.1 /5', '3.7 /5', '3.1 /5', '2.9 /5', '3.3 /5', '2.8 /5',
'3.5 /5', '2.7 /5', '2.5 /5', '3.2 /5', '2.6 /5', '4.5 /5',
'4.3 /5', '4.4 /5', '4.9/5', '2.1/5', '2.0/5', '1.8/5', '4.6 /5',
'4.9 /5', '3.0 /5', '4.8 /5', '2.3 /5', '4.7 /5', '2.4 /5',
'2.1 /5', '2.2 /5', '2.0 /5', '1.8 /5'], dtype=object)
zomato.rate = zomato.rate.astype(str)
zomato.rate = zomato.rate.apply(lambda x : x.replace('/5','')).astype(float)
zomato.head()
| url | address | name | online_order | book_table | rate | votes | phone | location | rest_type | dish_liked | cuisines | cost | reviews_list | menu_item | type | city | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | https://www.zomato.com/bangalore/jalsa-banasha... | 942, 21st Main Road, 2nd Stage, Banashankari, ... | Jalsa | True | True | 4.1 | 775 | 080 42297555\r\n+91 9743772233 | south_bangalore | Casual Dining | Pasta, Lunch Buffet, Masala Papad, Paneer Laja... | North Indian, Mughlai, Chinese | 800.0 | [('Rated 4.0', 'RATED\n A beautiful place to ... | [] | Buffet | Banashankari |
| 1 | https://www.zomato.com/bangalore/spice-elephan... | 2nd Floor, 80 Feet Road, Near Big Bazaar, 6th ... | Spice Elephant | True | False | 4.1 | 787 | 080 41714161 | south_bangalore | Casual Dining | Momos, Lunch Buffet, Chocolate Nirvana, Thai G... | Chinese, North Indian, Thai | 800.0 | [('Rated 4.0', 'RATED\n Had been here for din... | [] | Buffet | Banashankari |
| 2 | https://www.zomato.com/SanchurroBangalore?cont... | 1112, Next to KIMS Medical College, 17th Cross... | San Churro Cafe | True | False | 3.8 | 918 | +91 9663487993 | south_bangalore | Cafe, Casual Dining | Churros, Cannelloni, Minestrone Soup, Hot Choc... | Cafe, Mexican, Italian | 800.0 | [('Rated 3.0', "RATED\n Ambience is not that ... | [] | Buffet | Banashankari |
| 3 | https://www.zomato.com/bangalore/addhuri-udupi... | 1st Floor, Annakuteera, 3rd Stage, Banashankar... | Addhuri Udupi Bhojana | False | False | 3.7 | 88 | +91 9620009302 | south_bangalore | Quick Bites | Masala Dosa | South Indian, North Indian | 300.0 | [('Rated 4.0', "RATED\n Great food and proper... | [] | Buffet | Banashankari |
| 4 | https://www.zomato.com/bangalore/grand-village... | 10, 3rd Floor, Lakshmi Associates, Gandhi Baza... | Grand Village | False | False | 3.8 | 166 | +91 8026612447\r\n+91 9901210005 | south_bangalore | Casual Dining | Panipuri, Gol Gappe | North Indian, Rajasthani | 600.0 | [('Rated 4.0', 'RATED\n Very good restaurant ... | [] | Buffet | Banashankari |
zomato['rate'] = zomato['rate'].fillna(zomato['rate'].mean())
zomato['cost'] = zomato['cost'].fillna(zomato['cost'].mean())
zomato['book_table'] = pd.get_dummies(zomato['book_table'], drop_first=True)
zomato.head()
| url | address | name | online_order | book_table | rate | votes | phone | location | rest_type | dish_liked | cuisines | cost | reviews_list | menu_item | type | city | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | https://www.zomato.com/bangalore/jalsa-banasha... | 942, 21st Main Road, 2nd Stage, Banashankari, ... | Jalsa | True | 1 | 4.1 | 775 | 080 42297555\r\n+91 9743772233 | south_bangalore | Casual Dining | Pasta, Lunch Buffet, Masala Papad, Paneer Laja... | North Indian, Mughlai, Chinese | 800.0 | [('Rated 4.0', 'RATED\n A beautiful place to ... | [] | Buffet | Banashankari |
| 1 | https://www.zomato.com/bangalore/spice-elephan... | 2nd Floor, 80 Feet Road, Near Big Bazaar, 6th ... | Spice Elephant | True | 0 | 4.1 | 787 | 080 41714161 | south_bangalore | Casual Dining | Momos, Lunch Buffet, Chocolate Nirvana, Thai G... | Chinese, North Indian, Thai | 800.0 | [('Rated 4.0', 'RATED\n Had been here for din... | [] | Buffet | Banashankari |
| 2 | https://www.zomato.com/SanchurroBangalore?cont... | 1112, Next to KIMS Medical College, 17th Cross... | San Churro Cafe | True | 0 | 3.8 | 918 | +91 9663487993 | south_bangalore | Cafe, Casual Dining | Churros, Cannelloni, Minestrone Soup, Hot Choc... | Cafe, Mexican, Italian | 800.0 | [('Rated 3.0', "RATED\n Ambience is not that ... | [] | Buffet | Banashankari |
| 3 | https://www.zomato.com/bangalore/addhuri-udupi... | 1st Floor, Annakuteera, 3rd Stage, Banashankar... | Addhuri Udupi Bhojana | False | 0 | 3.7 | 88 | +91 9620009302 | south_bangalore | Quick Bites | Masala Dosa | South Indian, North Indian | 300.0 | [('Rated 4.0', "RATED\n Great food and proper... | [] | Buffet | Banashankari |
| 4 | https://www.zomato.com/bangalore/grand-village... | 10, 3rd Floor, Lakshmi Associates, Gandhi Baza... | Grand Village | False | 0 | 3.8 | 166 | +91 8026612447\r\n+91 9901210005 | south_bangalore | Casual Dining | Panipuri, Gol Gappe | North Indian, Rajasthani | 600.0 | [('Rated 4.0', 'RATED\n Very good restaurant ... | [] | Buffet | Banashankari |
get_dummies_location = pd.get_dummies(zomato.location)
get_dummies_location.head()
| east_bangalore | north_bangalore | south_bangalore | west_bangalore | |
|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 |
| 1 | 0 | 0 | 1 | 0 |
| 2 | 0 | 0 | 1 | 0 |
| 3 | 0 | 0 | 1 | 0 |
| 4 | 0 | 0 | 1 | 0 |
get_dummies_service_type = pd.get_dummies(zomato.type)
get_dummies_service_type.head()
| Buffet | Cafes | Delivery | Desserts | Dine-out | Drinks & nightlife | Pubs and bars | |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 3 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 4 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
final_zom = pd.concat([zomato,get_dummies_service_type, get_dummies_location], axis = 1)
final_zom.head()
| url | address | name | online_order | book_table | rate | votes | phone | location | rest_type | ... | Cafes | Delivery | Desserts | Dine-out | Drinks & nightlife | Pubs and bars | east_bangalore | north_bangalore | south_bangalore | west_bangalore | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | https://www.zomato.com/bangalore/jalsa-banasha... | 942, 21st Main Road, 2nd Stage, Banashankari, ... | Jalsa | True | 1 | 4.1 | 775 | 080 42297555\r\n+91 9743772233 | south_bangalore | Casual Dining | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 1 | https://www.zomato.com/bangalore/spice-elephan... | 2nd Floor, 80 Feet Road, Near Big Bazaar, 6th ... | Spice Elephant | True | 0 | 4.1 | 787 | 080 41714161 | south_bangalore | Casual Dining | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 2 | https://www.zomato.com/SanchurroBangalore?cont... | 1112, Next to KIMS Medical College, 17th Cross... | San Churro Cafe | True | 0 | 3.8 | 918 | +91 9663487993 | south_bangalore | Cafe, Casual Dining | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 3 | https://www.zomato.com/bangalore/addhuri-udupi... | 1st Floor, Annakuteera, 3rd Stage, Banashankar... | Addhuri Udupi Bhojana | False | 0 | 3.7 | 88 | +91 9620009302 | south_bangalore | Quick Bites | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 4 | https://www.zomato.com/bangalore/grand-village... | 10, 3rd Floor, Lakshmi Associates, Gandhi Baza... | Grand Village | False | 0 | 3.8 | 166 | +91 8026612447\r\n+91 9901210005 | south_bangalore | Casual Dining | ... | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
5 rows × 28 columns
final_zom = final_zom.drop(["name","rest_type","location", 'cuisines','dish_liked', 'reviews_list',"menu_item","type",
"city","url","address","phone","rest_type",'votes'],axis=1)
final_zom.head()
| online_order | book_table | rate | cost | Buffet | Cafes | Delivery | Desserts | Dine-out | Drinks & nightlife | Pubs and bars | east_bangalore | north_bangalore | south_bangalore | west_bangalore | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | True | 1 | 4.1 | 800.0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 1 | True | 0 | 4.1 | 800.0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 2 | True | 0 | 3.8 | 800.0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 3 | False | 0 | 3.7 | 300.0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 4 | False | 0 | 3.8 | 600.0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
x = final_zom.drop(['rate'], axis = 1)
y = final_zom['rate']
x.columns
Index(['online_order', 'book_table', 'cost', 'Buffet', 'Cafes', 'Delivery',
'Desserts', 'Dine-out', 'Drinks & nightlife', 'Pubs and bars',
'east_bangalore', 'north_bangalore', 'south_bangalore',
'west_bangalore'],
dtype='object')
y.describe()
count 51717.000000 mean 3.700449 std 0.395391 min 1.800000 25% 3.500000 50% 3.700449 75% 3.900000 max 4.900000 Name: rate, dtype: float64
x.shape
(51717, 14)
from sklearn.tree import DecisionTreeClassifier
from sklearn import metrics
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size=0.20)
x_train.shape, x_test.shape
((41373, 14), (10344, 14))
from sklearn.ensemble import RandomForestRegressor RForest=RandomForestRegressor(n_estimators=500,random_state=None,min_samples_leaf=2,max_depth=6) RForest.fit(x_train,y_train) y_predict=RForest.predict(x_test) from sklearn.metrics import r2_score r2_score(y_test,y_predict)
list(x.columns)
['online_order', 'book_table', 'cost', 'Buffet', 'Cafes', 'Delivery', 'Desserts', 'Dine-out', 'Drinks & nightlife', 'Pubs and bars', 'east_bangalore', 'north_bangalore', 'south_bangalore', 'west_bangalore']
So from above we came to know that Decision Tree Regressor has 98.7% accuracy which means our model is perfectly working
def returnFeatureImportance(est, col):
feature_importance = est.feature_importances_
feature_importance_rel = 100.0 * (feature_importance / feature_importance.max())
sorted_idx = np.argsort(feature_importance_rel)
featuresNames = []
featureImps =[]
featureImps_Rel = []
for item in sorted_idx[::-1][:]:
featuresNames.append(np.asarray(col)[item])
featureImps.append(feature_importance[item])
featureImps_Rel.append(feature_importance_rel[item])
featureImportance = pd.DataFrame([featuresNames, featureImps, featureImps_Rel]).transpose()
featureImportance.columns = ['FeatureName', 'Importance', 'Relative Importance']
return featureImportance
feature_cols=['online_order',
'book_table',
'cost',
'Buffet',
'Cafes',
'Delivery',
'Desserts',
'Dine-out',
'Drinks & nightlife',
'Pubs and bars',
'east_bangalore',
'north_bangalore',
'south_bangalore',
'west_bangalore']
zomato['location'].unique()
array(['south_bangalore', nan, 'east_bangalore', 'west_bangalore',
'north_bangalore'], dtype=object)
import six
import sys
sys.modules['sklearn.externals.six'] = six
#conda install python-graphviz
from io import StringIO
plt.figure(figsize=(18,8))
rest_locations = zomato['location'].value_counts()[:20]
sns.barplot(rest_locations, rest_locations.index, palette='Set2')
plt.title("Top 20 foodie areas in Banglore")
plt.show();
C:\Users\Madhukar\anaconda3\lib\site-packages\seaborn\_decorators.py:36: FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
#x = zomato_en.iloc[:,[2,3,5,6,7,8,9,11]]
#y = zomato_en['rate']
#Getting Test and Training Set
#x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=None)
#x_train.head()
#y_train.head()
from sklearn import metrics
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.neighbors import KNeighborsRegressor
from sklearn.svm import SVR
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import r2_score
from sklearn.tree import DecisionTreeRegressor
clf = DecisionTreeRegressor(criterion='squared_error', splitter='best', max_depth=4, min_samples_split=2,
min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None,
random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, ccp_alpha=0.0)
clf.fit(x_train, y_train)
DecisionTreeRegressor(max_depth=4)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
DecisionTreeRegressor(max_depth=4)
dtree_pred = clf.predict(x_test)
# Calculate the absolute errors
dtree_errors = abs(dtree_pred - y_test)
# Calculate mean absolute percentage error (MAPE)
mape = 100 * (dtree_errors / y_test)
# Calculate and display accuracy
dtree_accuracy = 100 - np.mean(mape)
print('Accuracy for Decision tree regressor is :', round(dtree_accuracy, 1), '%.')
Accuracy for Decision tree regressor is : 92.5 %.
from sklearn.tree import export_graphviz
from io import StringIO
from IPython.display import Image
import pydotplus
dot_data = StringIO()
export_graphviz(clf, out_file=dot_data,
filled=True, rounded=True,
special_characters=True, feature_names=feature_cols, class_names=['0', '1'])
dot_data = dot_data.getvalue().replace('&', '&')
graph = pydotplus.graph_from_dot_data(dot_data)
graph.write_png('diabetes.png')
Image(graph.create_png())
FR=returnFeatureImportance(clf,x_train.columns).sort_values(by='Relative Importance',ascending=False)
FR.head(10)
| FeatureName | Importance | Relative Importance | |
|---|---|---|---|
| 0 | book_table | 0.802545 | 100.0 |
| 1 | cost | 0.134195 | 16.721133 |
| 2 | Desserts | 0.028172 | 3.510387 |
| 3 | online_order | 0.022435 | 2.795427 |
| 4 | Cafes | 0.01087 | 1.354426 |
| 5 | south_bangalore | 0.001784 | 0.222269 |
| 6 | west_bangalore | 0.0 | 0.0 |
| 7 | north_bangalore | 0.0 | 0.0 |
| 8 | east_bangalore | 0.0 | 0.0 |
| 9 | Pubs and bars | 0.0 | 0.0 |
from sklearn.ensemble import RandomForestRegressor
est = RandomForestRegressor(n_estimators=500, criterion='squared_error', max_depth=6, min_samples_split=2, min_samples_leaf=1,
min_weight_fraction_leaf=0.0, max_features='auto', max_leaf_nodes=None,
min_impurity_decrease=0.0, bootstrap=True, oob_score=False, n_jobs=None,
random_state=None, verbose=0, warm_start=False, ccp_alpha=0.0,
max_samples=None)
est.fit(x_train, y_train)
C:\Users\Madhukar\anaconda3\lib\site-packages\sklearn\ensemble\_forest.py:413: FutureWarning: `max_features='auto'` has been deprecated in 1.1 and will be removed in 1.3. To keep the past behaviour, explicitly set `max_features=1.0` or remove this parameter as it is also the default value for RandomForestRegressors and ExtraTreesRegressors.
RandomForestRegressor(max_depth=6, max_features='auto', n_estimators=500)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
RandomForestRegressor(max_depth=6, max_features='auto', n_estimators=500)
rf_pred = est.predict(x_test)
# Calculate the absolute errors
rf_errors = abs(rf_pred - y_test)
# Calculate mean absolute percentage error (MAPE)
mape = 100 * (rf_errors / y_test)
# Calculate and display accuracy
rf_accuracy = 100 - np.mean(mape)
print('Accuracy for Random Forest regressor is :', round(rf_accuracy, 1), '%.')
Accuracy for Random Forest regressor is : 92.6 %.
import graphviz
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
# Split the data into training and testing sets
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)
# Create a linear regression object
model = LinearRegression()
# Train the model using the training sets
model.fit(x_train, y_train)
# Make predictions on the testing set
y_pred = model.predict(x_test)
# Calculate the root mean squared error
rmse = mean_squared_error(y_test, y_pred, squared=False)
print(f"RMSE: {rmse:.2f}")
RMSE: 0.36
from sklearn.neighbors import KNeighborsRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
# Split the data into training and testing sets
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)
# Create a KNN regressor object
model = KNeighborsRegressor(n_neighbors=5)
# Train the model using the training sets
model.fit(x_train, y_train)
# Make predictions on the testing set
y_pred = model.predict(x_test)
# Calculate the root mean squared error
rmse = mean_squared_error(y_test, y_pred, squared=False)
print(f"RMSE: {rmse:.2f}")
RMSE: 0.37
FR=returnFeatureImportance(est,x_train.columns)
FR
| FeatureName | Importance | Relative Importance | |
|---|---|---|---|
| 0 | book_table | 0.727431 | 100.0 |
| 1 | cost | 0.15453 | 21.243307 |
| 2 | online_order | 0.048808 | 6.709618 |
| 3 | Desserts | 0.027893 | 3.834519 |
| 4 | Cafes | 0.0211 | 2.900609 |
| 5 | west_bangalore | 0.005301 | 0.728699 |
| 6 | east_bangalore | 0.004776 | 0.656557 |
| 7 | Buffet | 0.003509 | 0.482449 |
| 8 | south_bangalore | 0.003026 | 0.416042 |
| 9 | Drinks & nightlife | 0.001816 | 0.249705 |
| 10 | Pubs and bars | 0.000532 | 0.073177 |
| 11 | north_bangalore | 0.000477 | 0.065541 |
| 12 | Delivery | 0.0004 | 0.055028 |
| 13 | Dine-out | 0.000399 | 0.054809 |